package Test_2019_3_19.servlet;

import Test_2019_3_19.util.JdbcUtil;
import com.alibaba.fastjson.JSON;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@WebServlet(name = "DeleteServlet", urlPatterns = {"/atb/delete.do"})
public class DeleteServlet extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 解决中文乱码
        response.setContentType("application/text; charset=utf-8");
        // 获取批量删除的序号数组
        String[] id = request.getParameterValues("id[]");
        // 判断添加还是编辑
        int rlt = 0;
        for (String ids : id) {
            // 执行批量隐藏操作
            JdbcUtil jdbc = new JdbcUtil();
            rlt = jdbc.delete(Integer.parseInt(ids));
        }
        // (判断操作是否成功)转化json格式准备
        Map<String, Object> mjs = new HashMap<String, Object>();
        mjs.put("rlt", rlt);
        // 把数据转化为json格式
        String Json = JSON.toJSONString(mjs);
        response.getWriter().write(Json);
    }
}